package gold.digger;

import gold.vo.TreeNode;

/**
 * Created by fanzhenyu02 on 2020/3/1.
 */
public class LC230 {

    int count = 1, res;

    public int kthSmallest(TreeNode root, int k) {
        midTravel(root, k);
        return res;
    }

    public void midTravel(TreeNode root, int k) {
        if (root == null) {
            return;
        }

        midTravel(root.left, k);
        if (count++ == k) {
            res = root.val;
            return;
        }
        midTravel(root.right, k);
    }


    public static void main(String[] args) {
        LC230 an = new LC230();
        TreeNode root = TreeNode.createTree("5,3,6,2,4,null,null,1");
        System.out.println(an.kthSmallest(root, 3));
    }
}
